package com.qf.service2.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.domain2.Student;
import com.qf.mapper2.StudentMapper;
import com.qf.service2.StudentService;
import com.qf.utils.MapperUtils;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    @Override
    public List<Student> findAll() {
        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        List<Student> students = mapper.findAll();
        MapperUtils.close();
        return students;
    }

    @Override
    public List<Student> findById(Integer id) {
        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        List<Student> students = mapper.findById(id);
        MapperUtils.close();
        return students;
    }

    @Override
    public List<Student> findAll_classes() {
        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        List<Student> students = mapper.findAll_classes();
        MapperUtils.close();
        return students;
    }

    @Override
    public List<Student> findAll_anno() {
        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        List<Student> students = mapper.findAll_anno();
        MapperUtils.close();
        return students;
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize) {
        //① 设置分页参数
        PageHelper.startPage(pageNum,pageSize);

        //② 执行查询
        StudentMapper mapper = MapperUtils.getMapper(StudentMapper.class);
        List<Student> students = mapper.findAll();
        MapperUtils.close();

        //③ 将查询到的结果封装到PageInfo返回
        return new PageInfo(students);
    }
}
